package com.sys.util;

import java.io.Serializable;



import lombok.Setter;

/*
 * @author:汪思超
 * @class:返回结果的工具类
 * @date:2021.3.7
 * */
@Setter
public class SysResult implements Serializable {

	/**
	 * 序列化
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * @param:status状态码，200为成功，500为失败
	 */
	private int status;

	/**
	 * @param:data  附带保存的数据
	 */
	private Object data;
	
	/**
	 * @param:msg  消息
	 */
	private String msg;
	
	/**
	 * 带参构造器
	 */
	public SysResult(int status) {
		super();
		this.status = status;
	}

	/**
	 * 不带参构造器
	 */
	public SysResult() {
		super();
	}
	
	/**
	 * @param:status状态码
	 * @method:成功返回方法
	 */
	public static SysResult ok() {
		return new SysResult(200);
	}
	
	public static SysResult ok(Object data) {
		return new SysResult(200,data);
	}
	
	public static SysResult ok(Object data,String msg) {
		return new SysResult(200,data,msg);
	}
	
	/**
	 * @param:status状态码
	 * @method:失败的返回方法
	 */
	public static SysResult error() {
		return new SysResult(500);
	}

	public static SysResult error(Object data) {
		return new SysResult(500,data);
	}
	
	public static SysResult error(Object data,String msg) {
		return new SysResult(500,data,msg);
	}
	
	/**
	 * 得到当前状态码
	 */
	public int getStatus() {
		return status;
	}

	public SysResult(int status, Object data) {
		super();
		this.status = status;
		this.data = data;
	}

	public Object getData() {
		return data;
	}

	public String getMsg() {
		return msg;
	}

	public SysResult(int status, Object data, String msg) {
		super();
		this.status = status;
		this.data = data;
		this.msg = msg;
	}
}
